//
// Created by 李传智 on 2018/4/12.
//

#include "GLVideoView.h"
#include "Texture.h"

void GLVideoView::render(VideoData data) {
    mutex.lock();
    if (!this->window) {
        mutex.unlock();
        return;
    }
    if (!this->texture) {
        this->texture = Texture::create();
        this->texture->init(this->window, data.width, data.height, data.format);
    }
    this->texture->draw(data.src, data.width, data.height);
    mutex.unlock();
}

void GLVideoView::setRender(void *window) {
    mutex.lock();
    this->window = window;
    mutex.unlock();
}

void GLVideoView::close() {
    mutex.lock();
    if (texture) {
        texture->destroy();
        texture = 0;
    }
    mutex.unlock();
}